package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.position.CoolPosition;
import cn.da.shuai.cool.system.model.entity.position.SearchPositionVo;
import cn.da.shuai.cool.system.model.entity.position.UpdatePositionVo;
import cn.da.shuai.cool.system.service.service.ICoolPositionService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/position")
@Tag(name = "岗位管理", description = "岗位管理相关接口")
public class CoolPositionController {

    private final ICoolPositionService positionService;

    public CoolPositionController(ICoolPositionService positionService) {
        this.positionService = positionService;
    }

    @Operation(summary = "分页查询岗位列表")
    @GetMapping("/page")
    public R<Page<CoolPosition>> pageList(SearchPositionVo searchPositionVo, Page page) {
        return R.ok(positionService.pageList(searchPositionVo, page));
    }

    @Operation(summary = "新增岗位")
    @PostMapping
    public R<Void> savePosition(@RequestBody UpdatePositionVo updatePositionVo) {
        positionService.savePosition(updatePositionVo);
        return R.ok();
    }

    @Operation(summary = "更新岗位")
    @PutMapping
    public R<Void> updatePosition(@RequestBody UpdatePositionVo updatePositionVo) {
        positionService.updatePosition(updatePositionVo);
        return R.ok();
    }

    @Operation(summary = "删除岗位")
    @DeleteMapping("/{id}")
    public R<Void> deletePosition(@PathVariable Long id) {
        positionService.deletePosition(id);
        return R.ok();
    }

    @Operation(summary = "获取所有岗位")
    @GetMapping("/list")
    public R<List<CoolPosition>> listAllPositions() {
        return R.ok(positionService.listAllPositions());
    }
}